import {areaList} from '../../utils/areaData';
import {addOrder}from '../../api/pm'
// import { areaList } from '@vant/area-data';
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    outshow:{
      type:Boolean,
      value:"",
    },
    itemdetail:{
type:Object,
value:{}
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    areaList: {
      province_list: areaList.province_list, //省
      city_list: areaList.city_list,  //市
      county_list: areaList.county_list //区
  },
  innershow:false,
  phone:"",
  number:1,
  area:"",
  areadetail:"",
  },

  /**
   * 组件的方法列表
   */
  methods: {

  // 关闭外部操作菜单
outclose(){
  this.setData({ 
    outshow: false,
innershow:false,
phone:"",
number:1,
area:"",
areadetail:"", 
  });
},
  // 显示内部操作菜单
  showarea(){
    this.setData({ innershow: true });
    console.log(this.properties.itemdetail)
  },
        // 关闭内部操作菜单
  innerclose() {
    this.setData({
       innershow: false,
      
    });
  },
  phone(event) {
    // event.detail 为当前输入的值
    console.log(event.detail);
    this.setData({
      phone:event.detail
    })
  },
  // number(event) {
   
  //   console.log(event.detail);
  //   this.setData({
  //     number:event.detail
  //   })
  // },
  onStepperChange(e) {
    console.log(e.detail);
    this.setData({
      number: e.detail,
     
    });
    // 这里可以调用接口更新数量或者做其他逻辑处理
  },
  areadetail(event) {
    // event.detail 为当前输入的值
    console.log(event.detail);
    this.setData({
      areadetail:event.detail
    })
  },
  conf(e){
    // console.log(e.detail.values[0].name+" "+e.detail.values[1].name+" "+e.detail.values[2].name);
    this.setData({
      innershow:false,
    area:e.detail.values[0].name+" "+e.detail.values[1].name+" "+e.detail.values[2].name
    })
  
    },
    // cancl(e){
    
    //   this.setData({
    //     innershow:false,
    //   })
    
    //   },
  confirm(){
    console.log(this.data.phone)
console.log(this.data.area)
console.log(this.data.number)
console.log(this.properties.areadetail)
    addOrder({
      data:{
          "goodsId":  this.properties.itemdetail.id,
          "goodsNum":this.data.number,
          "phone": this.data.phone,
          "expressArea": this.data.area,
          "expressAddr": this.data.areadetail
      },
      callBack: (res) => {
        // console.log(res)
        wx.showToast({
          title: '兑换成功',
          duration: 500,
        })
        this.setData({
          outshow:false,
          innershow:false,
          phone:"",
          number:1,
          area:"",
          areadetail:"", 
        })
        this.triggerEvent('myEvent');
      }
    })


    },
 

  },

  attached(){
  }
})